package ex_9_deadLockTest;

public class DealThread extends Thread{
    
    Object lock1 = new Object();
    Object lock2 = new Object();

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        if("AA".equals(name)){
            try {
                synchronized (lock1){
                    System.out.println("thread name = " + name + " lock1 ");
                    Thread.sleep(3000);
                    synchronized (lock2){
                        System.out.println("thread name = " + name + " lock2 ");
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }else {
            try {
                synchronized (lock2){
                    System.out.println("thread name = " + name + " lock2 ");
                    Thread.sleep(3000);
                    synchronized (lock1){
                        System.out.println("thread name = " + name + " lock1 ");
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
